package com.general.template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.general.template.utils.Pages;
import com.general.template.utils.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.general.template.mapper.PowerDimensionMapper;
import com.general.template.pojo.PowerDimension;
import com.general.template.service.PowerDimensionService;
/**
 * @Author: 杰哥
 * Date: 2021/2/16 18:07
 * @Description:
**/

@Service
public class PowerDimensionServiceImpl extends ServiceImpl<PowerDimensionMapper, PowerDimension> implements PowerDimensionService{

    @Override
    public Pages<PowerDimension> pageList(Pages<PowerDimension> pages) {
        PowerDimensionMapper mapper = getBaseMapper();
        IPage<PowerDimension> page = new Page<>(pages.getCurrentPage(),pages.getPageSize());
        QueryWrapper<PowerDimension> wrapper = new QueryWrapper<>();
        for (Map.Entry<String, Object> entry : pages.getParams().entrySet()) {
            if (!StringUtils.isNullOrEmpty(entry.getValue())){
                if (!"dimensionName".equals(entry.getKey())){
                    wrapper.eq(StringUtils.upperCharToUnderLine(entry.getKey()),entry.getValue());
                }else{
                    wrapper.like("dimension_name","%"+entry.getValue()+"%");
                }
            }
        }
        wrapper.orderByDesc("jobs_id","id");
        IPage<PowerDimension> selectPage = mapper.selectPage(page, wrapper);
        pages.setList(selectPage.getRecords());
        pages.setTotalCount((int) selectPage.getTotal());
        pages.setTotalPage((int) selectPage.getPages());
        return pages;
    }
}
